package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.entity.Wages;
import com.woniuxy.propertyjava.service.WagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : author
 * @create 2022/7/7 15:29
 */
@RestController
public class WagesController {
    @Autowired
    WagesService wagesService;

    @PostMapping("/wages/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Wages>> getWagesByPage(@PathVariable("pageIndex") int pageIndex,
                                                           @PathVariable("pageSize") int pageSize,
                                                           @RequestBody  Wages wages) {
        PageBean<Wages> pageBean = wagesService.getWagesPageBean(wages, pageIndex, pageSize);
        ResponseResult<PageBean<Wages>> responseResult = new ResponseResult<PageBean<Wages>>(200, "ok", pageBean);
        return responseResult;
    }

    @PostMapping("/wages")
    public ResponseResult addWages(@RequestBody Wages wages) {
        wagesService.insertWages(wages);
        ResponseResult responseResult=new ResponseResult<>(200,"添加成功",null);
        return responseResult;
    }

    @PutMapping("/wages")
    public ResponseResult changewages(@RequestBody Wages wages) {
        wagesService.updateWages(wages);
        ResponseResult responseResult=new ResponseResult<>(200,"修改成功",null);
        return responseResult;
    }

    @DeleteMapping("/wages/{wagesId}")
    public ResponseResult reducewages(@PathVariable("wagesId") int wagesId) {
        wagesService.deleteWages(wagesId);
        ResponseResult responseResult=new ResponseResult<>(200,"删除成功",null);
        return responseResult;
    }
}
